package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.SystemDictionary;
import cn.wolfcode.crm.mapper.SystemDictionaryMapper;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.ISystemDictionaryService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SystemDictionaryServiceImpl implements ISystemDictionaryService {

    @Autowired
    private SystemDictionaryMapper systemDictionaryMapper;

    @Override
    public PageInfo<SystemDictionary> selectByQo(QueryObject qo) {

        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<SystemDictionary> list = systemDictionaryMapper.selectAll();
        PageInfo<SystemDictionary> info = new PageInfo<>(list);
        return info;
    }

    @Override
    public SystemDictionary selectBydeptId(Long deptId) {
        SystemDictionary systemDictionary = systemDictionaryMapper.selectByPrimaryKey(deptId);
        return systemDictionary;
    }

    @Override
    public void saveOrUpdate(SystemDictionary systemDictionary) {
        if(systemDictionary.getId()==null){
            systemDictionaryMapper.insert(systemDictionary);
        }else{
            systemDictionaryMapper.updateByPrimaryKey(systemDictionary);
        }
    }

    @Override
    public void deleteBydeptId(Long deptId) {
        systemDictionaryMapper.deleteByPrimaryKey(deptId);
    }

    @Override
    public List<SystemDictionary> selectAll() {
        List<SystemDictionary> list = systemDictionaryMapper.selectAll();
        return list;
    }

    @Override
    public SystemDictionary selectById(Long parentId) {

        return systemDictionaryMapper.selectByPrimaryKey(parentId);
    }
}
